<?php
/*
+ ----------------------------------------------------------------------------------------------------+
|        e107 website system 
|        Plugin Admin File: e107_plugins/lightbox/admin_config.php
|        Email: support@free-source.net
|        $Revision: 330 $
|        $Date: 2007-02-12 23:22:29 +0200 (Mon, 12 Feb 2007) $
|        $Author: secretr $
|        Copyright Corllete Lab ( http://www.clabteam.com ) under GNU GPL License (http://gnu.org)
|        Support Sites : http://www.free-source.net/ | http://dev.e107bg.org/
+----------------------------------------------------------------------------------------------------+
*/
require_once("../../class2.php");
if(!getperms("P")){ header("location:".e_BASE."index.php"); exit; } 

$lan_file = e_PLUGIN."lightbox/languages/".e_LANGUAGE.".php";
include_lan($lan_file); 

//$qs = e_QUERY ? explode('.', e_QUERY) : array('', '');
$pageid = !e_QUERY ? 'config' : e_QUERY;

$csslist = '';
if( $pageid == 'config') {
    require_once(e_HANDLER."userclass_class.php"); 
    require_once(e_HANDLER."file_class.php");
    $fl = new e_file;
    $csslist = $fl->get_files(e_PLUGIN.'lightbox/src/css/themes', ".css|.CSS");
    sort($csslist);
}

function headerjs()
{
    global $csslist,$pageid;
    $hcss = '';
	if(!empty($csslist) && $pageid == 'config') {
    	foreach ($csslist as $cssth) {
            $hcss .= "
            <!-- All Window themes -->
            <link href='".e_PLUGIN."lightbox/src/css/themes/{$cssth['fname']}' rel='stylesheet' type='text/css' />";
        }
    }
    return $hcss;
}

require_once(e_ADMIN."auth.php");
require_once(e_HANDLER."form_handler.php");

// Start Session if it's not already started
if ($pref['user_tracking'] != "session") {
	session_start();
}

//Actions
if(isset($_POST['update_prefs'])) {
	//check
	if(!is_numeric($_POST['lightb_rspeed'])) {
		show_message(LB_LANADM_100, LAN_UPDATED_FAILED, true);
	} elseif(!is_numeric($_POST['lightb_bsize'])) {
		show_message(LB_LANADM_100, LAN_UPDATED_FAILED, true);
	}  elseif(!is_numeric($_POST['lightb_tmar'])) {
		show_message(LB_LANADM_100, LAN_UPDATED_FAILED, true);
	}  elseif(!is_numeric($_POST['lightb_rmar'])) { 
		show_message(LB_LANADM_100, LAN_UPDATED_FAILED, true);
	}  elseif(!is_numeric($_POST['lightb_bmar'])) { 
		show_message(LB_LANADM_100, LAN_UPDATED_FAILED, true);
	}  elseif(!is_numeric($_POST['lightb_lmar'])) { 
		show_message(LB_LANADM_100, LAN_UPDATED_FAILED, true);
	} else {
		if(!isset($_POST['set_default']) || !$_POST['set_default']) {
			$pref['lightb_rspeed'] = !$_POST['lightb_rspeed'] ? 1 : (intval($_POST['lightb_rspeed']) > 10 ? 10 : intval($_POST['lightb_rspeed']));
			$pref['lightb_bsize']  = !$_POST['lightb_bsize'] ? '0' : intval($_POST['lightb_bsize']);
			$_POST['lightb_tmar']  = !$_POST['lightb_tmar'] ? '0' : intval($_POST['lightb_tmar']);
			$_POST['lightb_rmar']  = !$_POST['lightb_rmar'] ? '0' : intval($_POST['lightb_rmar']);
			$_POST['lightb_bmar']  = !$_POST['lightb_bmar'] ? '0' : intval($_POST['lightb_bmar']);
			$_POST['lightb_lmar']  = !$_POST['lightb_lmar'] ? '0' : intval($_POST['lightb_lmar']);
			$pref['lightb_margin']  = $_POST['lightb_tmar'].','.$_POST['lightb_rmar'].','.$_POST['lightb_bmar'].','.$_POST['lightb_lmar'];
			$pref['lightb_window']  = !$_POST['lightb_window'] ? '0' : '1';
			$pref['lightb_wtheme']  = preg_match("/[^a-zA-Z0-9.\-_]/", $_POST['lightb_wtheme']) || empty($_POST['lightb_wtheme']) ? '' : trim($_POST['lightb_wtheme']);
		    $pref['lightb_wperms'] = $_POST['lightb_wperms'];
		    $pref['lightb_advwperms'] = $_POST['lightb_advwperms'];
        } else {
			$pref['lightb_rspeed'] = 7;
			$pref['lightb_bsize']  = 10;
			$pref['lightb_margin']  = '0,0,0,0';
			$pref['lightb_window']  = '1';
			$pref['lightb_wtheme']  = 'lightbox';
			$pref['lightb_wperms'] = e_UC_MEMBER;
			$pref['lightb_advwperms'] = e_UC_ADMIN;
		}
		
		save_prefs();
		show_message(LB_LANADM_150, LAN_UPDATED);
		$_SESSION['sessmsg'] = array(LB_LANADM_150, LAN_UPDATED);
		session_write_close();
		header("Location: ".e_SELF);
		exit;
	}
	
}
//session msgs - after-redirect messages
if(isset($_SESSION['sessmsg'])) {
  show_message($_SESSION['sessmsg'][0], $_SESSION['sessmsg'][1]);
  unset($_SESSION['sessmsg']);
}

//Show Admin pages
if($pageid == 'help') {
	$text = '
	<table width="98%">
		<tr>
			<td>
			'.LB_LAN_9.'
			</td>
		</tr>
		<tr>
			<td>
				<strong>'.LB_LAN_10.'</strong> -> <img src="'.e_PLUGIN.'lightbox/images/bb.png" alt="" /><br /><br />
				
				<strong>'.LB_LAN_11.'</strong> <br />'.LB_LAN_12.'<br /><br />
				
				<strong>'.LB_LAN_13.'</strong><br />
				'.LB_LAN_14.' <br />
				'.LB_LAN_15.'<br />
				'.LB_LAN_16.'<br />
				'.LB_LAN_17.'<br />
				'.LB_LAN_18.'<br /><br />
				
				<strong>'.LB_LAN_19.'</strong><br />
				<div style="font-size: 13px">
					'.LB_LAN_20.'
				</div>
				'.LB_LAN_21.' 
				<br /><br />
				<div class="code_highlight code-box" style="unicode-bidi: embed; direction: ltr;">'.LB_LAN_22.'<code><font color="#000000">
				&lt;a href="http://domain.com/images/myimage.jpg" rel="lightbox" title="My Image"&gt;View Image&lt;/a&gt;
				</font></code></div>
				'.LB_LAN_23.'<a href="'.e_PLUGIN.'lightbox/example/1.jpg" rel="lightbox" title="My Image">View Image</a><br /><br />
				<strong>'.LB_LAN_24.'</strong><br />
				'.LB_LAN_25.'<br /><br />
				<div style="font-size: 13px">
					[lightbox=http://domain.com/images/myimage_1.jpg|My Image 01|roadtrip]View Image 01[/lightbox]<br />
					[lightbox=http://domain.com/images/myimage_2.jpg|My Image 02|roadtrip]View Image 02[/lightbox]
				</div>
				'.LB_LAN_21.' <br /><br />
				<div class="code_highlight code-box" style="unicode-bidi: embed; direction: ltr;">'.LB_LAN_22.'<br /><code><font color="#000000">
				&lt;a href="http://domain.com/images/myimage_1.jpg" rel="lightbox[roadtrip]" title="My Image 01"&gt;View Image 01&lt;/a&gt;<br />
				&lt;a href="http://domain.com/images/myimage_2.jpg" rel="lightbox[roadtrip]" title="My Image 02"&gt;View Image 02&lt;/a&gt;
				</font></code></div><br />
				'.LB_LAN_23.'<br /><br /><a href="'.e_PLUGIN.'lightbox/example/1.jpg" rel="lightbox[roadtrip]" title="My Image 01">View Image 01</a>
				<a href="'.e_PLUGIN.'lightbox/example/2.jpg" rel="lightbox[roadtrip]" title="My Image 02">View Image 02</a>
				<br /><br />

				<strong>'.LB_LAN_26.'</strong><br />
				'.LB_LAN_27.'
				<div style="font-size: 13px">
					[lightbox=http://domain.com/images/myimage.jpg|My Image||left][img]http://domain.com/images/myimage_THUMB.jpg[/img][/lightbox]
				</div><br />
				'.LB_LAN_21.' <br /><br />
				<div class="code_highlight code-box" style="unicode-bidi: embed; direction: ltr;">'.LB_LAN_22.'<br /><code><font color="#000000">
				&lt;div style="float: left;"&gt;<br />
				&lt;a href="http://domain.com/images/myimage.jpg" rel="lightbox" title="My Image"&gt;<br />&lt;img src="http://domain.com/images/myimage_THUMB.jpg" /&gt;&lt;/a&gt;<br />
				&lt;/div&gt;
				</font></code></div><br />
				'.LB_LAN_23.'<br /><br /><a href="'.e_PLUGIN.'lightbox/example/1.jpg" rel="lightbox[My Birthday]" title="My Image"><img src="'.e_PLUGIN.'lightbox/example/1_thumb.jpg" alt="" /></a><br /><br />
			</td>
		</tr>
	</table>
	';

	$ns->tablerender(LB_LANADM_3, $text);

} elseif($pageid == 'config') {   
	$ns->tablerender(LB_LANADM_2, show_options());
} else {
    $_SESSION['sessmsg'] = array(LB_LANADM_101, LAN_ERROR);
    session_write_close();
    header("Location:".e_PLUGIN."lightbox/admin_config.php?config"); 
    exit;
}

require_once(e_ADMIN."footer.php"); 
exit;

function show_options()
{
	global $pref,$csslist,$tp;
	
	//theme select box
	$hcss = '';
	if(!empty($csslist)) {
    	$themeopt = form::form_select_open('lightb_wtheme');
    	$themeopt .= form::form_option(LB_LANADM_15, (!$pref['lightb_wtheme']), '');
    	foreach ($csslist as $cssth) {
            $opt = str_replace('.css', '', strtolower($cssth['fname']));
            $optval = $opt;
            if($opt == 'default') {
                $optval = 'dialog';
            } 
            $opt = ucfirst($opt);
            $themeopt .= form::form_option($opt, ($optval == $pref['lightb_wtheme']), $optval);
        }
        $themeopt .= form::form_select_close();
    } else {
        $themeopt = 'N/A';
    }
    
    //v1.3 margin
    list($_POST['lightb_tmar'],$_POST['lightb_rmar'],$_POST['lightb_bmar'],$_POST['lightb_lmar']) = explode(',', $pref['lightb_margin']);

    //theme select box end
	$txt = "
	<form method='post' action='".e_SELF."'>
	<table class='fborder' style='width:95%'>
	<tr>
		<td class='fcaption' colspan='2' style='text-align:center'>".LB_LANADM_11."</td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_4."</td>
		<td class='forumheader3' style='width:25%'>".form::form_text('lightb_rspeed', 2, lbvarset($pref['lightb_rspeed'], 7, true), 2)."</td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_5."</td>
		<td class='forumheader3' style='width:25%'>".form::form_text('lightb_bsize', 4, lbvarset($pref['lightb_bsize'], 10, true), 4)."</td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_7."</td>
		<td class='forumheader3' style='width:25%'><input class='tbox' id='lightb_tmar' name='lightb_tmar' size='3' maxlength='3' type='text' value='".lbvarset($_POST['lightb_tmar'], '0', true)."' /> px</td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_8."</td>
		<td class='forumheader3' style='width:25%'><input class='tbox' id='lightb_rmar' name='lightb_rmar' size='3' maxlength='3' type='text' value='".lbvarset($_POST['lightb_rmar'], '0', true)."' /> px</td>
	</tr>
		<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_9."</td>
		<td class='forumheader3' style='width:25%'><input class='tbox' id='lightb_bmar' name='lightb_bmar' size='3' maxlength='3' type='text' value='".lbvarset($_POST['lightb_bmar'], '0', true)."' /> px</td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_10."</td>
		<td class='forumheader3' style='width:25%'><input class='tbox' id='lightb_lmar' name='lightb_lmar' size='3' maxlength='3' type='text' value='".lbvarset($_POST['lightb_lmar'], '0', true)."' /> px</td>
	</tr>
	<tr>
		<td class='fcaption' colspan='2' style='text-align:center'>".LB_LANADM_12."</td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_13."</td>
		<td class='forumheader3' style='width:25%'>".form::form_checkbox('lightb_window', 1, $pref['lightb_window'])."</td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_14."</td>
		<td class='forumheader3' style='width:25%'>
            {$themeopt}
    ";
    if($pref['lightb_window']) {
        $altxt = htmlspecialchars("<h4>".LB_LANADM_16."</h4><div style=\"margin: 10px\"><br />".LB_LANADM_17."</div>",ENT_COMPAT,CHARSET);
        $altxt = str_replace("'", "\'", $altxt);
        $wtxt = htmlspecialchars("<div style=\"margin: 10px\"><br />".LB_LANADM_17."<br /><br /><input type=\"button\" value=\"".LB_LAN_7."\" class=\"button\" onclick=\"Windows.closeAll();return false;\" /></div>",ENT_COMPAT,CHARSET);
        $wtxt = str_replace("'", "\'", $wtxt);
        $wttl = $tp -> toJS(LB_LANADM_16);
        
        $txt .= "
                <br /><a href='#' onclick=\"lbaTest('{$altxt}', 350); return false;\">".LB_LANADM_16." - alert</a>
                <br /><a href='#' onclick=\"lbwTest('{$wtxt}', 350,'".$wttl."'); return false;\">".LB_LANADM_16." - BBcode</a>
                <script type='text/javascript'>
                <!--
                   
                    function lbaTest(s, w) {
                        var testv = document.getElementById('lightb_wtheme').value;
                        Dialog.alert(s, 
                            {windowParameters: {className: testv, width: w},
                             okLabel: '".LB_LAN_7."',
                             buttonClass: 'button'
                            });
                    }
         
                    function lbwTest(s, w,ttl) {
                        var testv = document.getElementById('lightb_wtheme').value;
                    	var testWin = new Window('content_win', 
                    							{
                                                    className: testv, resizable: true, 
                                                    hideEffect:Effect.Fade, showEffect:Effect.Appear, minWidth: w,
                                                    title: ttl,wiredDrag: true
                                                });
                    	testWin.getContent().update(s);
                    	testWin.setDestroyOnClose();
                        testWin.showCenter(); 
                        
                	}
                // -->
                </script>
        ";
    }
    $txt .=  "
        </td>
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_18."</td>
		<td class='forumheader3' style='width:25%'>".r_userclass("lightb_wperms", $pref['lightb_wperms'], "off", "main,admin,member,public,guest,classes")."</td>  
	</tr>
	<tr>
		<td class='forumheader3' style='width:75%'>".LB_LANADM_19."</td>
		<td class='forumheader3' style='width:25%'>".r_userclass("lightb_advwperms", $pref['lightb_advwperms'], "off", "nobody,main,admin,member,public,guest,classes")."</td>  
	</tr>
	<tr>
		<td class='forumheader' colspan='2' style='text-align:right; vertical-align: top;'>
            <div style='float: left;'>".form::form_checkbox('set_default', '1')." ".LB_LANADM_6."</div>
            <input type='submit' class='button' name='update_prefs' value='".LAN_SAVE."' />
        </td>
	</tr>
	</table>
	</form>
	";
	return $txt;
}
function show_message($message, $caption='', $error=false) {
	global $ns;
	$ns->tablerender($caption, "<div style='text-align:center; font-weight: bold'>".($error ? "<span style='color: #8B0000'>".$message."</span>" : $message)."</div>");
}
?>